<template>
  <div>
    <div>
      <template>
        <div class="info-detail">
          <div class="info-detail-title mb-10">{{ data.Title }}</div>
          <div
            class="info-detail-desc mb-10"
            v-if="data.InfoType == 2 && data.CheckType == 'ZCLX0002'"
          >
            【{{ data.InfoTypeName }}•<span v-if="data.CheckTypeName"
              >{{ data.CheckTypeName }}•</span
            >{{ data.ItemTypeName }}•{{ data.SafetyLevelName }}•{{
              data.EmergencyLevelName
            }}】
          </div>
          <div
            class="info-detail-desc mb-10"
            v-if="data.InfoType == 2 && data.CheckType !== 'ZCLX0002'"
          >
            【{{ data.InfoTypeName }}•<span v-if="data.CheckTypeName"
              >{{ data.CheckTypeName }}•</span
            >{{ data.SafetyLevelName }}•{{ data.EmergencyLevelName }}】
          </div>
          <div class="info-detail-desc mb-10" v-else>
            【{{ data.InfoTypeName }}•{{ data.SafetyLevelName }}•{{
              data.EmergencyLevelName
            }}】
          </div>
          <div class="info-detail-company">
            <span>{{ data.CompanyName }}</span>
            <span class="ml-10 mr-10">{{ data.CreateChnName }}</span>
            <span>{{ data.CreateDate }}</span>
          </div>
          <van-divider />
          <div class="info-detail-cont" v-html="data.Content"></div>

          <div>
            <van-row class="mb-20" v-if="data.Attachs && data.Attachs.length">
              <van-col :span="4"> 附件： </van-col>
              <van-col :span="20">
                <div
                  class="mb-10 file-list"
                  v-for="(item, index) in data.Attachs"
                  :key="index"
                >
                  <a
                    style="color: #00c1de; word-break: break-all"
                    @click="_showFileByPdf(item)"
                  >
                    {{ item.FileName }} {{ item.AttName }}{{ item.AttExt }}
                  </a>
                  <div></div>
                  {{ item.AttName }}{{ item.AttExt }}
                </div>
              </van-col>
            </van-row>
            <van-row
              class="mb-20"
              v-if="data.FeedBackAttachs && data.FeedBackAttachs.length"
            >
              <van-col :span="4"> 反馈： </van-col>
              <van-col :span="20">
                <div
                  class="mb-10 file-list"
                  v-for="(item, index) in data.FeedBackAttachs"
                  :key="index"
                >
                  <a
                    style="color: #00c1de; word-break: break-all"
                    @click="_showFileByPdf(item)"
                  >
                    {{ item.AttName }}{{ item.AttExt }}
                  </a>
                  <div></div>
          
                </div>
              </van-col>
            </van-row>
            <van-row v-if="data.TNames && data.TNames.length">
              <van-col :span="4">
                <!-- <img src="@/assets/Images/AppIcon/icon_list_verify.png"/> -->
                检查表
              </van-col>
              <van-col :span="20">
                <div
                  class="mb-10"
                  v-for="(item, index) in data.TNames"
                  :key="index"
                  style="color: blue;"
                  @click="goTemplateDetail(index)"
                >
                  {{ item }}
                </div>
              </van-col>
            </van-row>
          </div>
          <div class="sign-for" v-if="data.IsSign">
            签收：<span class="mr-10">{{ data.SignChnName }}</span
            ><span>{{ data.SignTime }}</span>
          </div>
        </div>
        <van-button
          v-if="!data.IsSign"
          class="info-detail-btn"
          type="warning"
          @click="Sign"
          >签 收</van-button
        >
        <van-button
          v-if="data.AllowCreatePlan && !data.HasDangerCheckPlan"
          class="info-detail-btn"
          type="info"
          @click="lookInfoCheckplan()"
          >创建检查计划</van-button
        >
        <div
          class="info-detail-btn"
          v-if="data.AllowCreatePlan && data.HasDangerCheckPlan"
        >
          <van-button
            class="info-detail-editbtn"
            type="info"
            @click="addCheckTask()"
            >创建检查计划</van-button
          >
          <van-button
            class="info-detail-editbtn"
            type="primary"
            @click="lookInfoCheckplan()"
            >查看检查计划</van-button
          >
        </div>
      </template>
    </div>
  </div>
</template>
 

<script>
import { detail, Sign } from "@/api/info";
import PdfPreView from "@/components/Attach/PdfPreView";
export default {
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      filter: {
        id: "",
      },
      data: {},
      showPdf: false,
      pdfUrl: "",
      isJG:false
    };
  },
  created() {
    if(this.$store.state.CompanyType=='JG'){this.isJG=true}
    this.filter.id = this.$route.query.id;
    if (this.filter.id) {
      this.getDetail();
    }
  },
  components: {
    PdfPreView,
  },

  methods: {
    getDetail() {
      this.loading = true;
      detail(this.filter).then((res) => {
        console.log(res, "res");
        res.data.Attachs = JSON.parse(res.data.Attachs);
        res.data.FeedBackAttachs= JSON.parse(res.data.FeedBackAttachs)
        if (res.data.TNames) {
          res.data.TNames = res.data.TNames.split(",");
        }
        this.data = res.data;
        this.loading = false;
      });
    },
    Sign() {
      const _this = this;
      Sign(this.filter).then((res) => {
        this.$dialog
          .alert({
            title: "提示",
            message: "签收成功",
          })
          .then(() => {
            _this.$router.goRefresh();
          });
      });
    },
    // 创建检查计划 Danger/CheckTask
    addCheckTask() {
      this.$router.push({
        name: "CheckTask",
        params: {
          SourceID: this.filter.id,
        },
      });
    },
    // 查看检查计划
    lookInfoCheckplan() {
   
      this.$router.push({
                path: "/StartPlan",
                query: {
                  SourceID: this.filter.id,
                },
            });
    },

    // 附件详情
		_showFileByPdf(item) {
			// console.log(item,'sdvfdvdcd')
      //this.$router.push("/Attach/AatachDetail?attCode=" + item.AttCode+'&url='+item.FilePath);
      this.$router.push("/CommonInfo/ShowAttach?name="+item.FileName+"&"+"url=" +item.FilePath)

		},
    goTemplateDetail(index){
      let id=this.data.TemplateList[index].ID
      let url = this.isJG?"/Danger/DangerTemplateDetailJG":"/Danger/DangerTemplateDetail"
      this.$router.push({
        path: url,
        //query: { tCode: item.TCode },
        query: { tCode: id ,isRead:true},
      });
    }
  },
};
</script>

<style lang="less" scoped>
.info-detail {
  min-height: 100vh;
  background-color: #fff;
  padding: 20px;
  color: #333;
  font-size: 10px;
  padding-bottom: 80px;
  .info-detail-title {
    font-size: 18px;
    text-align: center;
    color: orange;
  }
  .info-detail-desc,
  .info-detail-company,
  .sign-for {
    text-align: center;
  }
  .info-detail-cont {
    min-height: 100px;

    /deep/ p {
      font-size: 13px !important;
    }
  }
  .sign-for {
    text-align: left;
    color: #f00;
  }
}
.info-detail-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40px;

  border-radius: 0;
  .info-detail-editbtn {
    width: 50%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border-radius: 0;
  }
}
.file-list {
  color: blue;
}
</style>